/*------------------手机号----------------------*/
var userName = document.getElementById("userName");  //获取用户名节点对象
userName.onfocus = userName.onblur = userName.onkeyup = checkUserName;

function checkUserName(e){
	var _e = window.event||e;
	var v = userName.value;  //用户名中的内容
	var control_group = document.querySelector(".control_group");  //获取box节点对象
	var tip = document.querySelector(".tips_judge");//信息提示容器节点对象
	var jingshi = tip.firstElementChild;//获取显示提示信息内容的节点对象
	var errors = tip.lastElementChild;
	//_e.type
	if(_e.type=="focus"){  //获取焦点事件
		if(v.length==0){  //文本框中的内容为空时，显示默认提示信息
			tip.style.display = "none";
			control_group.className = "control_group clearfix control_bor";
			//jingshi.innerHTML = "";
			errors.innerHTML="";
			return false;
		}
	}
	
	if(_e.type=="blur"){
		if(v.length==0){
			tip.style.display = "inline";
			control_group.className = "control_group clearfix control_red";
			//jingshi.innerHTML = "";
			errors.innerHTML="请输入手机号码";
			return; false
		}
	}
	
	/*其他情况（用户输入的时候或点击注册按钮的时候）*/
	if(v.length==0){  //文本框为空的情况下
		tip.style.display = "inline";
		control_group.className = "control_group clearfix control_red";
		errors.innerHTML = "请输入手机号码";
		return false;
	}else{  //文本框不为空的情况
		if(regExpManger.mobileReg.test(v)){  //格式正确
			tip.style.display = "none";
			control_group.className = "control_group clearfix";
			return true;
		}else{
			tip.style.display = "inline";
			control_group.className = "control_group clearfix control_red";
			errors.innerHTML = "手机号码格式错误";
			return false;
		}
	}
	
}
/*------------------手机号----------------------*/
var userName1 = document.getElementById("userName1");  //获取用户名节点对象
userName1.onfocus = userName1.onblur = userName1.onkeyup = checkUserName1;

function checkUserName1(e){
	var _e = window.event||e;
	var v = userName1.value;  //用户名中的内容
	var control_group = document.getElementById("control_groups");  //获取box节点对象
	var tip = document.getElementById("tips_judge1");//信息提示容器节点对象
	var jingshi = tip.firstElementChild;//获取显示提示信息内容的节点对象
	var errors = tip.lastElementChild;
	//_e.type
	if(_e.type=="focus"){  //获取焦点事件
		if(v.length==0){  //文本框中的内容为空时，显示默认提示信息
			tip.style.display = "none";
			control_group.className = "control_group clearfix control_bor";
			//jingshi.innerHTML = "";
			errors.innerHTML="";
			return false;
		}
	}
	
	if(_e.type=="blur"){
		if(v.length==0){
			tip.style.display = "inline";
			control_group.className = "control_group clearfix control_red";
			//jingshi.innerHTML = "";
			errors.innerHTML="请输入手机号码";
			return; false
		}
	}
	
	/*其他情况（用户输入的时候或点击注册按钮的时候）*/
	if(v.length==0){  //文本框为空的情况下
		tip.style.display = "inline";
		control_group.className = "control_group clearfix control_red";
		errors.innerHTML = "请输入手机号码";
		return false;
	}else{  //文本框不为空的情况
		if(regExpManger.mobileReg.test(v)){  //格式正确
			tip.style.display = "none";
			control_group.className = "control_group clearfix";
			return true;
		}else{
			tip.style.display = "inline";
			control_group.className = "control_group clearfix control_red";
			errors.innerHTML = "手机号码格式错误";
			return false;
		}
	}
	
}
/*------------------验证码----------------------*/
var code = document.getElementById("register_verifycode");  //获取用户名节点对象
code.onfocus = code.onblur = code.onkeyup = checkCode;
var code2 = document.getElementById("code2");

function checkCode(e){
	var _e = window.event||e;
	var v = code.value;  //用户名中的内容
	var control_group = code.parentNode;  //获取box节点对象
	var tip = code.nextElementSibling;//信息提示容器节点对象
	var jingshi = tip.firstElementChild;//获取显示提示信息内容的节点对象
	var errors = tip.lastElementChild;
	//_e.type
	if(_e.type=="focus"){  //获取焦点事件
		if(v.length==0){  //文本框中的内容为空时，显示默认提示信息
			tip.style.display = "none";
			control_group.className = "control_group clearfix control_bor";
			//jingshi.innerHTML = "";
			errors.innerHTML="";
			return false;
		}
	}
	
	if(_e.type=="blur"){
		if(v.length==0){
			tip.style.display = "inline";
			control_group.className = "control_group clearfix control_red";
			//jingshi.innerHTML = "";
			errors.innerHTML="请输入验证码";
			return; false
		}
	}
	
	/*其他情况（用户输入的时候或点击注册按钮的时候）*/
	if(v.length==0){  //文本框为空的情况下
		tip.style.display = "inline";
		control_group.className = "control_group clearfix control_red";
		errors.innerHTML = "请输入验证码";
		return false;
	}else{  //文本框不为空的情况
		if(code.value==code2.value){  //格式正确
			tip.style.display = "none";
			control_group.className = "control_group clearfix";
			return true;
		}else{
			tip.style.display = "inline";
			control_group.className = "control_group clearfix control_red";
			errors.innerHTML = "验证码格式错误";
			return false;
		}
	}
}
/*------------------短信验证----------------------*/
var duanxin = document.getElementById("register_code");  //获取用户名节点对象
duanxin.onfocus = duanxin.onblur = duanxin.onkeyup = checkDuanXin;


function checkDuanXin(e){
	var _e = window.event||e;
	var v = duanxin.value;  //用户名中的内容
	var control_group = duanxin.parentNode;  //获取box节点对象
	var tip = duanxin.nextElementSibling;//信息提示容器节点对象
	var jingshi = tip.firstElementChild;//获取显示提示信息内容的节点对象
	var errors = tip.lastElementChild;
	//_e.type
	if(_e.type=="focus"){  //获取焦点事件
		if(v.length==0){  //文本框中的内容为空时，显示默认提示信息
			tip.style.display = "none";
			control_group.className = "control_group clearfix control_bor";
			//jingshi.innerHTML = "";
			errors.innerHTML="";
			return false;
		}
	}
	
	if(_e.type=="blur"){
		if(v.length==0){
			tip.style.display = "inline";
			control_group.className = "control_group clearfix control_red";
			//jingshi.innerHTML = "";
			errors.innerHTML="请输入验证码";
			return; false
		}
	}
	
	/*其他情况（用户输入的时候或点击注册按钮的时候）*/
	if(v.length==0){  //文本框为空的情况下
		tip.style.display = "inline";
		control_group.className = "control_group clearfix control_red";
		errors.innerHTML = "请输入验证码";
		return false;
	}else{  //文本框不为空的情况
		if(regExpManger.numReg.test(v)){  //格式正确
			tip.style.display = "none";
			control_group.className = "control_group clearfix";
			return true;
		}else{
			tip.style.display = "inline";
			control_group.className = "control_group clearfix control_red";
			errors.innerHTML = "验证码格式错误";
			return false;
		}
	}
}

/*------------------密码验证----------------------*/
var tbPassword1 = document.getElementById("tbPassword_1");  //获取用户名节点对象
tbPassword1.onfocus = tbPassword1.onblur = tbPassword1.onkeyup = checkPassword;


function checkPassword(e){
	var _e = window.event||e;
	var v = tbPassword1.value;  //用户名中的内容
	var control_group = document.querySelector(".control_group1");  //获取box节点对象
	var tip = tbPassword1.nextElementSibling;//信息提示容器节点对象
	var jingshi = tip.firstElementChild;//获取显示提示信息内容的节点对象
	var errors = tip.lastElementChild;
	//_e.type
	if(_e.type=="focus"){  //获取焦点事件
		if(v.length==0){  //文本框中的内容为空时，显示默认提示信息
			tip.style.display = "none";
			control_group.className = "control_group1 clearfix control_bor";
			//jingshi.innerHTML = "";
			errors.innerHTML="";
			return false;
		}
	}
	
	if(_e.type=="blur"){
		if(v.length==0){
			tip.style.display = "inline";
			tip.className="tips_judge pwdtop";
			control_group.className = "control_group1 clearfix control_red";
			//jingshi.innerHTML = "";
			errors.innerHTML="请输入密码";
			return false;
		}
	}
	
	/*其他情况（用户输入的时候或点击注册按钮的时候）*/
	if(v.length==0){  //文本框为空的情况下
		tip.style.display = "inline";
		tip.className="tips_judge pwdtop";
		control_group.className = "control_group1 clearfix control_red";
		errors.innerHTML = "请输入密码";
		return false;
	}else{  //文本框不为空的情况
		if(v.length>=6&&v.length<=20){ //长度符合
			tip.style.display = "inline";
			tip.className="tips_judge pwdtop";
			control_group.className = "control_group1 clearfix";
			errors.innerHTML = "可以使用";
			var leval = getLevel(v);
			switch(leval){
				case 1:
				tip.style.display = "inline";
				tip.className="tips_judge pwdtop";
				control_group.className = "control_group1 clearfix control_red";
				errors.innerHTML = "安全强度较弱，但是可以使用";
					break;
				case 2:
					tip.style.display = "inline";
					tip.className="tips_judge pwdtop";
					control_group.className = "control_group1 clearfix control_yellow";
					errors.innerHTML = "安全强度适中，可以使用三种以上的组合来提高安全强度"
					break;
				default:
					tip.style.display = "inline";
					tip.className="tips_judge pwdtop";
					control_group.className = "control_group1 clearfix control_green";
					errors.innerHTML = "你的密码很安全"
				
			}
			return true;
		}else{  //长度不符合
			tip.style.display = "inline";
			tip.className="tips_judge pwdtop";
			control_group.className = "control_group1 clearfix control_red";
			errors.innerHTML = "密码长度不正确"
			return false;
		}
	}
	
	
}

/*------------------注册按钮追踪和验证码的随机函数还有密码安全级别----------------------*/
var btn = document.getElementById("login_btn");
var agree =  document.getElementById("agree");
var regOne = document.getElementById("login-one");
var regTwo = document.getElementById("login-two");
var tip = tbPassword1.nextElementSibling;
var errors = tip.lastElementChild;
var control_group = userName.parentNode;

btn.onclick = function(){
		if(checkUserName()&&checkPassword){  
			location.href = "index.html";
			alert("登陆成功！");
		}	
}
var btn1 = document.getElementById("fast_login_btn");
btn1.onclick = function(){
	//console.log("1");
	if(agree.checked){
		if(checkPassword()&&checkCode&&checkDuanXin()){
			location.href = "index.html";
			alert("登陆成功！");
		}
	}else{
		tip.style.display = "inline";
		tip.className="tips_judge pwdtop";
		control_group.className = "control_group clearfix control_red";
		errors.innerHTML="";
	}
}


var hide = document.getElementById("hide");
//var code2 = document.getElementById("code2"); //隐藏域节点对象
var arr = ["a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z","A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z","0","1","2","3","4","5","6","7","8","9"];
/*点击验证码切换验证码并改变隐藏域的值*/
hide.onclick = function(){
	var str = "";
	for(var i = 0;i<4;i++){
		var index = parseInt(Math.random()*arr.length);
		str+=arr[index];
	}
	hide.innerHTML = str;
	code2.value = hide.innerHTML;
}

function getLevel(pwd){
	var leval = 0;  //级别
	var isHasWord = false;  //没有记录过
	var isHasNumber = false;  //没有记录过
	var isHasOther = false;   //没有记录过
	for(var i = 0;i<pwd.length;i++){
		//abc123&
		if(regExpManger.wordReg.test(pwd[i])){
			if(isHasWord){  //true
				continue;
			}else{   //
				isHasWord = true;
				leval+=1;
			}
		}else if(regExpManger.numReg.test(pwd[i])){
			if(isHasNumber){  //true
				continue;
			}else{   //
				isHasNumber = true;
				leval+=1;
			}
		}else{
			if(isHasOther){  //true
				continue;
			}else{   //
				isHasOther = true;
				leval+=1;
			}
		}
	}

	return leval; //级别
}
var loginNav = document.getElementById("loginNav");
var li1 = loginNav.firstElementChild;
var li2 = loginNav.lastElementChild;

li1.onclick = function(){
	li2.className="";
	li1.className="current";
	regOne.style.display = "block";
	regTwo.style.display = "none";
}
li2.onclick = function(){
	li1.className="";
	li2.className="current";
	regOne.style.display = "none";
	regTwo.style.display = "block";
}

